package com.kilomob.grady.handler.netty;

import io.netty.channel.ChannelInitializer;
import io.netty.channel.ChannelPipeline;
import io.netty.channel.socket.SocketChannel;

import java.util.Map;

import com.kilomob.grady.codec.ReceiveSerializeFrame;

/**
 * 
 * 
 *   
 * @author zhouzhixiang  
 * @date 2017年1月2日
 * @since 1.0
 */
public class MessageReceiveChannelInitializer extends ChannelInitializer<SocketChannel> {

    private ReceiveSerializeFrame frame = null;
    private String id;
    private String protocol;
    
    public MessageReceiveChannelInitializer(String protocol,String id,Map<String, Object> handlerMap) {
        this.id = id;
        this.protocol = protocol;
        this.frame = new ReceiveSerializeFrame(handlerMap);
    }
    
    
    public MessageReceiveChannelInitializer(Map<String, Object> handlerMap) {
        frame = new ReceiveSerializeFrame(handlerMap);
    }

    protected void initChannel(SocketChannel socketChannel) throws Exception {
        ChannelPipeline pipeline = socketChannel.pipeline();
        frame.select(this.protocol,this.id, pipeline);
    }
}
